package com.dsteiner.widgets.server.dao;

import com.dsteiner.widgets.client.ObjectUtil;

public class Change {

	private final String propertyName;
	private final Object oldValue;
	private final Object value;

	public Change(String propertyName, Object oldValue, Object value) {
		this.propertyName = propertyName;
		this.oldValue = oldValue;
		this.value = value;
	}
	
	public Object getOldValue() {
		return oldValue;
	}
	public Object getValue() {
		return value;
	}
	public String getPropertyName() {
		return propertyName;
	}

	@Override
	public int hashCode() {
		return propertyName.hashCode() + (oldValue != null ? oldValue.hashCode() : 0) + (value != null ? value.hashCode() : 0);
	}
	
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (!(obj instanceof Change))
			return false;
		Change other = (Change) obj;
		return ObjectUtil.equals(propertyName, other.propertyName) &&
		ObjectUtil.equals(oldValue, other.oldValue) &&
		ObjectUtil.equals(value, other.value);
	}
	
	@Override
	public String toString() {
		return propertyName+"|"+oldValue+"|"+value;
	}
}
